package com.cq.androidtools.room1

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.cq.androidtools.R

/**
 * 作者: CQ
 * 日期: 2021-04-22
 * 说明:
 */
public class RoomActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.room_activity)


        Thread {
            val bookDao = AppDataBase.getInstance(this).bookDao()
            bookDao.deleteAllUser()
            bookDao.deleteAll()
            bookDao.insertBook(Book(0, "a", 1, 100))
            bookDao.insertBook(Book(1, "b", 1, 2))
            bookDao.insertBook(Book(2, "c", 1, 3))
            bookDao.insertBook(Book(3, "d", 1, 4))
            val makeDao = AppDataBase.getInstance(this).makeDao()
            makeDao.insertMake(MakeBean(1 , 1,"语文", "98"))
            makeDao.insertMake(MakeBean(2 , 1,"数学", "98"))
            makeDao.insertMake(MakeBean(5 , 1,"数学", "30"))
            makeDao.insertMake(MakeBean(3 , 2,"语文", "100"))
            makeDao.insertMake(MakeBean(4 , 2,"数学", "100"))

            makeDao.selectMake().forEach {
//                Log.e("--", "-成绩 = $it")
            }
//
//
            val studentDao = AppDataBase.getInstance(this).studentDao()
            studentDao.insert(
                Student(1, "小名1", 11)
            )
            studentDao.insert(
                Student(2, "小名2", 11)
            )


            val userDao = AppDataBase.getInstance(this).userDao()
            userDao.getFromCompany1(11).forEach { Log.e("--", "--==") }

            Log.e("--", "成绩：" + userDao.selectCJ(1))
            Log.e("--", "时间：" + userDao.selectTime(1))
//            studentDao.insert(
//                Student(3, "小名3", 13)
//            )
//            studentDao.insert(
//                Student(4, "小名4", 14)
//            )

        }.start()


    }

}